﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;



namespace ModeloDesenvolvimento
{
    public class Db
    {
        public Db() {}

        //recupera string de conexao que esta no app.config
        public String RetornaStringConexao(String Conexao)
        {
            return ConfigurationManager.AppSettings[Conexao].ToString();
             // return Poligas_ERP.Properties.Settings.Default.Connection;
        }

        public SqlConnection AbreConexao(String conexao)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = RetornaStringConexao(conexao);

            if(conn.State !=ConnectionState.Open)
            conn.Open();

            return conn;
        }

        public void FechaConexao(SqlConnection conn)
        {
            if (conn.State != ConnectionState.Closed)
                conn.Close();
        }

        public SqlCommand getCommand(SqlConnection conn)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = conn;
            cmd.Parameters.Clear();

            return cmd;
        }


    }
}
